<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<!--<script type="text/javascript">
tinyMCE.init({
		// General options
		mode : "exact",
		elements : "elm2",
		theme : "advanced",
		skin : "o2k7",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>-->
<?php
echo "**********".$_GET['_a'];
if($_GET['_a']==1)
{
	$id = $_GET['_d'];
	$page = $_GET['page'];
	$st = $_REQUEST['_st'];
	$title = $_POST['title'];
	$desc = $_POST['desc'];
	$datetaken = $_POST['datetaken'];
	$name = $_POST['name'];
	$status = $_POST['status'];
	
	$path = "../gallery/";
	$thumb_path = "../gallery/thumb/";
	if($_FILES['pic']['type'] == "image/gif" || $_FILES['pic']['type'] == "image/pjpeg" || $_FILES['pic']['type'] == "image/jpeg" || $_FILES['pic']['type'] == "image/jpg")
	{
		$fname = $id.'pic'.time();
    	if($_FILES['pic']['type'] == "image/gif") $filetype = ".gif";
		else  $filetype = ".jpg";
		
		$newupload = $_FILES['pic']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['pic']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			mysql_query("update picture set Title='$title', Description='$desc', DateTaken='$datetaken', Name='$name', Status='$status', ApprovedDate=now(),Image='$photo1' where Id='$id'") or die(mysql_error());
	echo "<script>window.location='index.php?tc=picture';</script>";
	}
	else
	{
		mysql_query("update picture set Title='$title', Description='$desc', DateTaken='$datetaken', Name='$name', Status='$status', ApprovedDate=now() where Id='$id'") or die(mysql_error());
	echo "<script>window.location='index.php?tc=picture';</script>";
	}
}


$id = $_REQUEST['_d'];
$page = $_REQUEST['page'];
$st = $_REQUEST['st'];

if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>

<script type="text/javascript" src="includes/fancybox/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.fancybox-1.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="includes/fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<link rel="stylesheet" href="includes/fancybox_style.css" />

<script type="text/javascript">
		$(document).ready(function() {
			/*
			*   Examples - images
			*/

			$("a#1").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			
			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

			/*
			*   Examples - various
			*/

			
		});
	</script>
<?php
$q = mysql_fetch_array(mysql_query("select * from picture where Id='$id'"));
$u = mysql_fetch_array(mysql_query("select * from users where Id='$q[UserId]'"));
?>

<form name="edpic" action="index.php?tc=picture_view&_d=<?php echo $id;?>&page=<?php echo $page;?>&_a=1&_st=<?php echo $st;?>" method="post" enctype="multipart/form-data">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<thead>
<tr>
	<td colspan="3" align="left">
        <div style="float:left">Picture</div>
        <div style="float:right"><a href="index.php?tc=picture&page=<?php echo $page;?>&st=<?php echo $st;?>">Back</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Title</td>
    <td colspan="2" align="left"><input type="text" name="title" value="<?php echo $q["Title"];?>" ></td>
</tr>
<tr>
	<td align="right" width="150">Description</td>
    <td colspan="2" align="left">
    <textarea name="desc" id="elm2" cols="80" rows="5" wrap="soft"><?php echo $q["Description"];?></textarea>
    <script type="text/javascript">CKEDITOR.replace( 'desc',{skin : 'kama'});</script>
    </td>
</tr>
<tr>
	<td align="right" width="150">DateTaken</td>
    <td colspan="2" align="left"><input type="text" name="datetaken" value="<?php echo $q["DateTaken"];?>" ></td>
</tr>
<tr>
	<td align="right" width="150">Name</td>
    <td colspan="2" align="left"><input type="text" name="name" value="<?php echo $q["Name"];?>"></td>
</tr>
<tr>
	<td align="right" width="150">Image</td>
    <td width="234" align="left">
    <input name="pic" type="file" />
    </td>
    <td width="545" align="left">
    <a id="1" href="../gallery/<?php echo $q['Image'];?>"><img src="../gallery/thumb/<?php echo $q["Image"];?>" border="0" ></a></td>
</tr>
<tr>
	<td align="right" width="150">Submitted By</td>
    <td colspan="2" align="left"><?php echo $u["FirstName"]." ".$u["LastName"];?></td>
</tr>
<tr>
	<td align="right" width="150">Status</td>
    <td colspan="2" align="left">
    	<select name="status">
        	<option value="0" <?php if($q["Status"]==0) echo "selected";?>>Pending</option>
            <option value="1" <?php if($q["Status"]==1) echo "selected";?>>Approved</option>
       	</select>     
    </td> 
</tr>
<tr>
	<td colspan="3" style="padding-left:155px;">
    	<input type="submit" value="Update" >&nbsp;&nbsp;
    </td>
</tr>        
 
</table>
</form>